/* ----------------------------------------------------------------------------
   The Kiwi Toolkit - A Java Class Library
   Copyright (C) 1998-2008 Mark A. Lindner

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this library; if not, see <http://www.gnu.org/licenses/>.
   ----------------------------------------------------------------------------
*/

package com.hyperrealm.kiwi.event;

import java.awt.Dialog;

/** Event generated by one of the Kiwi dialog classes when it has been
 * dismissed via an <i>OK</i> or <i>Cancel</i> button. The event object
 * stores the type of dismissal.
 *
 * @see com.hyperrealm.kiwi.event.DialogDismissListener
 *
 * @author Mark Lindner
 */

public class DialogDismissEvent
{
  /** Dismissal type; the <i>Cancel</i> button was pressed. */
  public static final int CANCEL = 0;

  /** Dismissal type; the <i>OK</i> button was pressed. */
  public static final int OK = 1;

  private int type;
  private Object obj;
  private Dialog source;

  /** Construct a new <code>DialogDismissEvent</code>.
   *
   * @param source The dialog that is the source of this event.
   * @param type The dismissal type; one of the numeric constants defined
   * above.
   */

  public DialogDismissEvent(Dialog source, int type)
  {
    this(source, type, null);
  }

  /** Construct a new <code>DialogDismissEvent</code>.
   *
   * @param source The dialog that is the source of this event.
   * @param type The dismissal type; one of the numeric constants defined
   * above.
   * @param userObject An arbitrary user object to associate with this event.
   */

  public DialogDismissEvent(Dialog source, int type, Object userObject)
  {
    this.source = source;
    this.type = type;
    this.obj = userObject;
  }

  /** Get the source of this event.
   *
   * @return the <code>Dialog</code> that generated this event.
   */

  public Dialog getSource()
  {
    return(source);
  }

  /** Get the user object associated with this event.
   *
   * @return The user object associated with this event, or <code>null</code>
   * if none was associated.
   */

  public Object getUserObject()
  {
    return(obj);
  }

  /** Determine if the dialog was cancelled.
   *
   * @return <code>true</code> if the dialog was dismissed via the
   * <i>Cancel</i> button; equivalent to <code>getType() ==
   * CANCEL</code>.
   */

  public boolean isCancelled()
  {
    return(type == CANCEL);
  }

  /** Get the dismissal type.
   *
   * @return The dismissal type; one of the numeric constants defined above.
   */

  public int getType()
  {
    return(type);
  }
  
}

/* end of source file */
